/* nixonFTP
 * FTP client version 0.1
 * Copyright (C) 2010 NIXON Development Corporation.
 * All rights reserved.
 * http://members.shaw.ca/nixon.com
*/

package nixonftp;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

public class NXInit extends JApplet {

	@Override
	public void init() {
		main(new String[] { "applet" });
		final String useProxy = getParameter("proxy");
		String proxyHost = getParameter("proxyHost");
		String proxyPort = getParameter("proxyPort");
		String proxyUser = getParameter("proxyUser");
		String proxyPass = getParameter("proxyPass");
		if (useProxy != null) {
			System.out.println("Using proxy server " + proxyHost + ":" + proxyPort);
			System.setProperty("ftp.useProxy", "true");
			System.setProperty("ftp.proxyHost", proxyHost);
			System.setProperty("ftp.proxyPort", proxyPort);
			System.setProperty("java.net.socks.username", proxyUser);
			System.setProperty("java.net.socks.password", proxyPass);
		}
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				NXDragFeedbackLabel lbl = new NXDragFeedbackLabel();
				NixonFTP Ftp = new NixonFTP(getContentPane(), lbl);
				Ftp.setProxyType(useProxy);
				setGlassPane(lbl);
			}
		});
	}

	public static void main(String[] args) {
		String OSName = System.getProperty("os.name").toLowerCase();
		boolean isMac = OSName.startsWith("mac os x");
		boolean isWin = OSName.startsWith("windows");

		//System.setProperty("ftp.proxyUserName", proxyUserName);
		//System.setProperty("ftp.proxyPassword", proxyPassword);
		if (isMac) {
			System.setProperty("apple.laf.useScreenMenuBar", "true");
			System.setProperty("com.apple.mrj.application.apple.menu.about.name", "nixonFTP");
			System.setProperty("apple.awt.brushMetalLook", "true");
			try {
				UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			} catch (Exception ex) {
			}
		}

		if (!isMac) {
			try {
				for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
					if ("Nimbus".equals(info.getName())) {
						UIManager.setLookAndFeel(info.getClassName());
						break;
					}
				}
			} catch (Exception e) {
			}
		}

		(new NXIcon()).loadIcons();

		if (args.length >= 1) {
			if (args[0].equals("applet")) {
				return;
			}
		}

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				NixonFTP Ftp = new NixonFTP();
			}
		});
	}
}
